package com.briup.day16;

import java.util.*;

public class Test_Game {
    //初始化牌面值和权重值
    private static Map<String, Integer> map;

    static {
        map=new HashMap<>();
        map.put("3", 1);
        map.put("4", 2);
        map.put("5", 3);
        map.put("6", 4);
        map.put("7", 5);
        map.put("8", 6);
        map.put("9", 7);
        map.put("10", 8);
        map.put("J", 9);
        map.put("Q", 10);
        map.put("K", 11);
        map.put("A", 12);
        map.put("2", 13);
        map.put("小王", 14);
        map.put("大王", 15);
    }

    //根据牌面值，获取权重值
    public static int getWeight(String number) {
        Integer i = map.get(number);
        return i;
    }

    public static void main(String[] args) {
        /*
        * 1.生成54张排，需要三个集合
        * 花色colors  点数numbers  54张组合好的牌
        * */
        List<String> colors = new ArrayList<String>();
        List<String> numbers=new ArrayList<>();
        List<Card> cards=new ArrayList<>();
//        往colors里面存入四种花色
        Collections.addAll(colors,"♠","♦","♥","♣");
        Collections.addAll(numbers,"3","4","5","6","7","8","9","10","J","Q","K","A","2");
        for(int i=0;i<colors.size();i++){
            String color = colors.get(i);
            for(int j=0;j<numbers.size();j++){
                String number = numbers.get(j);
                int weight = getWeight(number);
                Card c=new Card(color,number,weight);
                cards.add(c);
            }

        }
        cards.add(new Card("","小王",getWeight("小王")));
        cards.add(new Card("","大王",getWeight("大王")));
        //将牌的顺序打乱 cards
        Collections.shuffle(cards);
        //发牌
        List<Card> player1=new ArrayList<>();
        List<Card> player2=new ArrayList<>();
        List<Card> player3=new ArrayList<>();
        List<Card> dipai=new ArrayList<>();
        //记录拿到的牌
        Card c=null;
        for(int i=0;i<cards.size();i++){
            c=cards.get(i);
            if(i>=cards.size()-3){
                dipai.add(c);
            }else if(i%3==0){
            player1.add(c);
            }else if(i%3==1){
                player2.add(c);
            }else {
                player3.add(c);
            }
    }
        //先排序，在看牌
        Comparator<Card> comp=new Comparator<Card>() {
        @Override
            public int compare(Card o1, Card o2) {
                return o1.getWeight()-o2.getWeight();
        }
    };
        Collections.sort(player1,comp);
        Collections.sort(player2,comp);
        Collections.sort(player3,comp);
        Collections.sort(dipai,comp);
        //将玩家名称和玩家牌存到map集合中
        Map<String,List<Card>> map=new HashMap<>();
        map.put("玩家一",player1);
        map.put("玩家二",player2);
        map.put("玩家三",player3);
        map.put("底牌",dipai);
        Set<String> set=map.keySet();
        for(String key:set){
            System.out.println(key+" "+map.get(key));
        }
    }
}
class Card {
    private String color;
    private String number;
    private int weight;

    public Card(String color, String number, int weight) {
        this.color = color;
        this.number = number;
        this.weight = weight;
    }

    public int getWeight() {
        return weight;
    }

    @Override
    public String toString() {
        return color + " " + number;
    }
}
